package com.zisuyi.uilibrary.view

import android.content.Context
import android.util.AttributeSet
import com.weilele.mvvm.widget.BaseEditText
import com.zisuyi.uilibrary.R
import com.zisuyi.uilibrary.view.FontTextView.Companion.setFont


/**
 * 若红楼梦空，亦初心不变
 * 作者：weijiale
 * 包名：com.real.money.easy.customview
 * 时间：2018/8/1 15:26
 * 描述：支持设置字体的textView
 */
open class FontEditText : BaseEditText {
    constructor(context: Context) : this(context, null)
    constructor(context: Context, attrs: AttributeSet?) : this(
        context,
        attrs,
        com.google.android.material.R.attr.editTextStyle
    )

    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    ) {
        initView(context, attrs, defStyleAttr)
    }


    private fun initView(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) {
        val attributes = context?.obtainStyledAttributes(attrs, R.styleable.FontEditText)
        val fontPath = attributes?.getString(R.styleable.FontTextView_fontAssetsPath)
        setFont(fontPath)
        attributes?.recycle()
    }
}